package main

/*
#include "test7.h"

// intentionally write the same LDFLAGS differently
#cgo CFLAGS : -I.
#cgo linux LDFLAGS: -L. -ltest7 -lstdc++
#cgo darwin LDFLAGS: -L. -ltest7 -lstdc++
*/
import "C"

import (
	"fmt"
	"unsafe"
)

func main() {
	length := 7
	var a = [7]C.BYTE{1, 2, 3, 4, 5, 6, 7}
	fmt.Println(a)
	// rlen := C.int(0)
	// var result []int
	result := make([]C.int, 10)
	end := C.test7(&a[0], C.int(length), (*C.int)(unsafe.Pointer(&result[0])))
	fmt.Println("end:", end, "a", a, "result", result)
}

func CArrayToGoArray(cArray unsafe.Pointer, size int) (goArray []int) {
	p := uintptr(cArray)
	for i := 0; i < size; i++ {
		j := *(*int)(unsafe.Pointer(p))
		goArray = append(goArray, j)
		p += unsafe.Sizeof(j)
	}
	return
}

// func main() {
//  goArray := CArrayToGoArray(unsafe.Pointer(&C.cArray[0]), 7)
//  fmt.Println(goArray)
// }
